#!/usr/bin/python3
# -*- coding:utf-8 -*-
""""
@Author: 李吉凯
@Email: lijk34925@hundsun.com
@Time: 2022/6/29 21:22
@File: assert_method.py
"""
from qturboframe.lib.webdriver import SeleniumError

from BladeFerm.Lib.Common import logger
from BladeFerm.hui2_app import FE

def assertResult(result, expectMessage='', checkMessage=''):
    if result:
        logger.info(f'期望结果是 {expectMessage}，检查信息是 {checkMessage}，断言成功 ')
        return True
    else:
        msg = "失败!"
        FE.driver.getScreen()
        logger.error('断言结果为：%s' % msg)
        raise SeleniumError("断言失败！期望信息为：{}，断言信息为：{}".format(expectMessage, checkMessage))

def assertTwoResult(expResult, resResult):
    expResult = expResult if isinstance(expResult, str) else str(expResult)
    resResult = resResult if isinstance(resResult, str) else str(resResult)
    logger.info(f'expResult:{expResult}, {type(expResult)}')
    logger.info(f'resResult:{resResult}, {type(resResult)}')
    if expResult == resResult:
        msg = "成功!"
        logger.info('断言结果为：%s' % msg)
        return True
    else:
        msg = "失败!"
        FE.driver.getScreen()
        logger.error('断言结果为：%s' % msg)
        raise SeleniumError(F"断言失败！期望信息为：{expResult}，断言信息为：{resResult}")

def checkAssert(express, errorMsg="Assert Fail"):
    logger.info(f"assert express: {express}")
    assert express, errorMsg
    logger.info('Assert successful!')